<?php
/**
 * Created by PhpStorm.
 * User: luohao
 * Date: 2016/10/10
 * Time: 15:17
 */

namespace App\Model;


use Illuminate\Database\Eloquent\Model;
use Mockery\CountValidator\Exception;

class UserModel extends Model
{
    protected $table = 'user';
    public $timestamps = false;

    /**
     * @param $username
     * @return mixed
     */
    public function findUserByUsername($username)
    {
        return $this->where('username',$username)->get();
    }

    public function findUserById($userid)
    {
        return $this->where('userid',$userid)->get();
    }

    public function getUser($username)
    {
        return $this->where('username','like',$username)->get();
    }

    public function deleteUserById($userid)
    {
        try {
            $this->where('userid',$userid)->delete();
        } catch(Exception $e) {
            $e->getMessage();
            return false;
        }
        return true;
    }

    public function addUser(array $UserInfo)
    {
        try {
            $this->insert($UserInfo);
        } catch (\PDOException $e) {
            $e->getMessage();
            return false;
        }
        return true;
    }

    public function editStatus($userid)
    {
        try {
            $this->where('userid', $userid)->update(['status' => 1]);
        } catch (\PDOException $e) {
            $e->getMessage();
            return false;
        }
        return true;
    }

}